<!-- 经营信息发布统计 -->
<template>
  <div>
    <HomeCard
      title="经营信息发布统计"
      isTimer
      headIcon="img_9"
      @checkedTimer="checkedTimer"
    >
      <template v-slot:content>
        <div class="business-info">
          <div class="business-info-left">
            <div class="business-info-list">
              <div
                class="business-info-item"
                v-for="item in businessList"
                :key="item.id"
              >
                <h4>{{ item.name }}</h4>
                <p>
                  <span :class="item.className">{{ item.num }}</span
                  ><span>条</span>
                </p>
                <div class="business-info-icon">
                  <img :src="item.imgUrl" />
                </div>
              </div>
            </div>
          </div>
          <div class="business-info-right">
            <HomeEcharts ref="EchartsRef" :echartsOption="echartsOption" />
          </div>
        </div>
      </template>
    </HomeCard>
  </div>
</template>

<script type="text/javascript">
import HomeCard from "@/pages/components/homeCard/index.vue";
import HomeEcharts from "@/pages/components/homeEcharts/index.vue";

import icon_6 from "../../assets/icon/icon_01 (6).png";
import icon_7 from "../../assets/icon/icon_01 (7).png";
import icon_10 from "../../assets/icon/icon_01 (10).png";

import { pubulishStatistics } from "@/api/home";

export default {
  name: "todo-page",
  components: {
    HomeCard,
    HomeEcharts,
  },
  data() {
    return {
      businessList: [
        {
          id: "1",
          name: "经营信息总数",
          num: 0,
          imgUrl: icon_6,
          className: "business-info-top",
        },
        {
          id: "2",
          name: "经营信息已接收",
          num: 0,
          imgUrl: icon_7,
          className: "business-info-center",
        },
        {
          id: "3",
          name: "经营信息被拒收",
          num: 0,
          imgUrl: icon_10,
          className: "business-info-bottom",
        },
      ],
      echartsOption: {
        backgroundColor: "#fff",
        legend: {
          itemWidth: 20,
          itemHeight: 4,
          // itemGap: 10,
          show: true,
          data: ["发布数量", "被接收数量", "被拒绝数量"],
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            lineStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(0, 255, 233,0)",
                  },
                  {
                    offset: 0.5,
                    color: "rgba(255, 255, 255,1)",
                  },
                  {
                    offset: 1,
                    color: "rgba(0, 255, 233,0)",
                  },
                ],
                global: false,
              },
            },
          },
        },
        dataZoom: [
          {
            // 设置滚动条的隐藏与显示
            show: true,
            // 设置滚动条类型
            type: "slider",
            // 设置背景颜色
            // backgroundColor: "#fefefe",
            // // 设置选中范围的填充颜色
            // fillerColor: "#2d8cf0",
            // // 设置边框颜色
            // borderColor: "#2d8cf0",
            // 是否显示detail，即拖拽时候显示详细数值信息
            showDetail: false,
            // 数据窗口范围的起始数值
            startValue: 0,
            // 数据窗口范围的结束数值（一页显示多少条数据）
            endValue: 3,
            // empty：当前数据窗口外的数据，被设置为空。
            // 即不会影响其他轴的数据范围
            filterMode: "empty",
            // 设置滚动条宽度，相对于盒子宽度
            width: "50%",
            // 设置滚动条高度
            height: 8,
            // 设置滚动条显示位置
            left: "center",
            // 是否锁定选择区域（或叫做数据窗口）的大小
            zoomLoxk: true,
            // 控制手柄的尺寸
            handleSize: 0,
            // dataZoom-slider组件离容器下侧的距离
            bottom: 3,
          },
          {
            // 没有下面这块的话，只能拖动滚动条，
            // 鼠标滚轮在区域内不能控制外部滚动条
            type: "inside",
            // 滚轮是否触发缩放
            zoomOnMouseWheel: false,
            // 鼠标滚轮触发滚动
            moveOnMouseMove: true,
            moveOnMouseWheel: true,
          },
        ],
        grid: {
          top: "15%",
          left: "10%",
          right: "5%",
          bottom: "15%",
          // containLabel: true
        },
        xAxis: [
          {
            type: "category",
            axisLine: {
              show: false,
              color: "#A582EA",
            },
            axisLabel: {
              color: "#A582EA",
              width: 100,
              margin: 20,
            },
            data: [],
          },
        ],

        yAxis: [
          {
            type: "value",
            min: 0,
            // max: 140,
            splitNumber: 4,
            splitLine: {
              show: true,
              lineStyle: {
                color: "#00BFF3",
                opacity: 0.23,
              },
            },
            axisLine: {
              show: false,
            },
            axisLabel: {
              show: true,
              margin: 20,
              textStyle: {
                color: "#333",
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [
          {
            name: "发布数量",
            type: "bar",
            barWidth: 10,
            itemStyle: {
              color: "#A582EA",
            },
            data: [20, 12, 31, 34, 31],
          },
          {
            name: "被接收数量",
            type: "bar",
            barWidth: 10,
            itemStyle: {
              color: "#f6ca9d",
            },
            data: [10, 20, 5, 9, 3],
          },
          {
            name: "被拒绝数量",
            type: "bar",
            barWidth: 10,
            itemStyle: {
              color: "#2d8cf0",
            },
            data: [1, 1, 2, 3, 1],
          },
        ],
      },
      cureentTimer: "Day",
    };
  },
  methods: {
    checkedTimer(item) {
      console.log(item, "选中时间");
      this.cureentTimer = item;
      this.pubulishStatisticsData();
    },
    async pubulishStatisticsData() {
      let params = {
        dimension: this.cureentTimer,
      };
      let data = await pubulishStatistics(params);
      if (data) {
        let publishCountArr = [];
        let receiveCountArr = [];
        let refulseCountArr = [];
        let dataArr = [];
        console.log(data, "122222");
        data.statisticsList.forEach((o) => {
          publishCountArr.push(o.publishCount);
          receiveCountArr.push(o.receiveCount);
          refulseCountArr.push(o.refulseCount);
          dataArr.push(o.countDate);
        });
        this.echartsOption.xAxis[0].data = dataArr;
        this.echartsOption.series.forEach((o) => {
          if (o.name == "发布数量") {
            o.data = publishCountArr;
          }
          if (o.name == "被接收数量") {
            o.data = receiveCountArr;
          }
          if (o.name == "被拒绝数量") {
            o.data = refulseCountArr;
          }
        });
        this.businessList.forEach((o) => {
          if (o.id == 1) {
            o.num = data.publishCount;
          }
          if (o.id == 2) {
            o.num = data.receiveCount;
          }
          if (o.id == 3) {
            o.num = data.refulseCount;
          }
        });
        this.$refs.EchartsRef.handleSetVisitChart();
      }
    },
  },
  mounted() {
    this.pubulishStatisticsData();
  },
};
</script>

<style lang="less" scoped>
.business-info {
  display: flex;
}
.business-info-left {
  flex: none;
  padding: 20px;
}

.business-info-item {
  position: relative;
  padding-left: 72px;
  margin-top: 20px;
  .business-info-icon {
    width: 54px;
    height: 54px;
    position: absolute;
    left: 0;
    top: 0;
    img {
      width: 100%;
    }
  }
  h4 {
    font-size: 16px;
    line-height: 24px;
    height: 24px;
  }
  p {
    height: 48px;
    span:nth-child(1) {
      font-size: 32px;
      font-weight: bold;
    }
    span:nth-child(2) {
      font-size: 14px;
      color: #888;
      margin-left: 5px;
    }
  }
}
.business-info-right {
  margin: 18px 0 0 15px;
  width: 100%;
  height: 310px;
  background: #f2f2f2;
}
.business-info-top {
  color: #0052d9;
}
.business-info-center {
  color: #1ccad5;
}
.business-info-bottom {
  color: #f45f6d;
}
</style>
